<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h3>count1 的值是：{{obj.count1}}</h3>
      <button @click="obj.count1+=1">count1 自增 +1</button>

      <hr>
      <h3>count2 的值是：{{obj.count2}}</h3>
      <button @click="addCount2">count2 自增 +1</button>
    </div>

    <script src="https://cdn.staticfile.org/vue/2.6.9/vue.js"></script>
    <script>
      const vm = new Vue({
        el: '#app',
        data: {
          obj: {
            count1: 0
          }
        },
        methods: {
          // 点击按钮，让 count2 自增 +1
          addCount2() {
            if(this.obj.count2 === undefined) {
              // 这个 count2 是后来才添加到 obj 上的属性；并不是 data 刚创建的时候，obj 就拥有的自带属性
              // this.obj.count2 = 0
              // Vue.set(this.obj, 'count2', 0)
              this.$set(this.obj, 'count2', 0)
            }
            this.obj.count2 += 1
          }
        }
      })
    </script>
  </body>
</html>
